<template>
  <div>
    <!-- 表格操作项 start  -->
    <template v-for="(item, index) in tableBtn">
      <Button v-if="showBtn(item.label)"
              :key="index"
              type="primary"
              :icon="item.icon"
              class="ivu-mr-8"
              @click="tableTopOperate(item.name)">{{ item.label }}</Button>
    </template>
    <!-- <Button icon="md-list"
                class="ivu-ml-8"
                v-show="tableBatchBtns && tableBatchBtns.length>0 && tableSelectData &&tableSelectData.length">批量操作</Button> -->
    <Dropdown class="ivu-ml-8"
              v-show="tableSelectData && tableSelectData.length>0"
              @on-click="handleClickItem">
      <Button>更多操作
        <Icon type="ios-arrow-down" />
      </Button>
      <DropdownMenu slot="list">
        <template v-for="(item, index) in tableBatchBtns">
          <DropdownItem v-if="showBtn(item.label)"
                        :key="index"
                        :name="item.name">{{item.label}}
          </DropdownItem>
        </template>
      </DropdownMenu>
    </Dropdown>
    <!-- 表格操作项 end  -->
  </div>
</template>
<script>
import dynamictablebtns from '@/mixins/dynamictablebtns'; // 混入通用代码
import { ApiRequest } from '@api/basePage';
import { mapGetters } from 'vuex';
import { getBtnsId } from '@/libs/btnsPermission'

export default {
  mixins: [
    dynamictablebtns
  ],
  data () {
    return {
    }
  },
  computed: {
    ...mapGetters('permissions/systemBtns', [
      'showBtn'
    ]),
  },
  methods: {
    handleClickItem (name) {
      if (name === 'CorrelaMultiple') {
        let curBtnId = getBtnsId('批量相关商品')
        sessionStorage.setItem('buttonId', curBtnId)
        let uuidArr = [];
        let skuNos = '';
        this.tableSelectData.forEach(item => {
          uuidArr.push(item.skuNo)
        });
        skuNos = uuidArr.join(',');
        let  data ={
            skuNos:uuidArr
        }
        ApiRequest('/sysback/productorg/checkPermission', 'post', data, false).then(res => {
          if (res.retStatus == '1' && res.retData.isHavePermission) {
            this.$router.push({ path: '/commodity/commodityManage/relatedGoodsManage/relatedGoodsManageCorrelaMultiple', query: { 'skuNo': skuNos } })
          } else {
            this.$Message.error(res.retData.message)
          }
        })


      }
    }
  }
}
</script>
